home *** CD-ROM | disk | FTP | other *** search
- Instructions for Making Your Own GOPHER IN A FOREST Objects
- ---------------------------------------------------------
- (ver 0.5)
-
-
- NOTE: I am maintaining an archive of GF objects on ion.rice.edu (as long
- as they don't take TOO much disk space). If you come up with something that's
- functional, I urge you to upload it to ion in /incoming. I will test them and
- move them to /pub/GFobjs. Feel free to download them from either location
- (at your own risk). Please try to limit your use of this server to nights
- and weekends.
-
-
- The new version of Gopher in a Forest has support for dynamically loading
- two types of objects. The first type of object is a subclass of Object and
- should (to be consistent) have a name ending with "Coord". This class allows
- you to put in your own algorithm for assigning node locations in 3d. TreeCoord
- is the default object used by Gopher in a Forest. It is already linked into
- the main program, and the source is present only as a programming example.
-
- The other type of object must be a subclass of View and should have a name
- ending in "View". This type of object allows customization of the actual
- display. Again, TreeView is the default view for Gopher in a Tree and is
- already linked into the program. If you try to modify TreeView or TreeCoord,
- be SURE to give them a new name (filename must match class name).
-
-
- The "Coord" objects are designed to be simple and easy to implement. Each
- Coord object must implement all of the following methods :
-
- -start:(Root *)top :(id)Pobject :(char *)path
- This method passes the pointer to the top of the gopher web (top) and
- the id of the GopherObj (discussed later) to your object. You should
- store these variables (if you will need them) and return. This method
- will be called once just after the object is created. The path
- variable contains the path of Tree.app in case you need to load
- your own .nib files, etc ...
-
- -(char *)help:window :view
- This method displays help and information about your object. There
- are 3 methods you can use to actually display the information. First
- and easiest is to ignore the passes variables and simply return a
- pointer to a null terminated string containing your help message. This
- message will be displayed for you. Second, you can use the window and
- view ids to display the message yourself (if, for example, you
- need to display an RTF file). You will need to makeKeyAndOrderFront
- the window, then display in the ScrollView. Be sure to return NULL
- so your message doesn't get erased. Finally, you can open your
- own window and do whatever you want. Just be sure to return NULL.
-
- -setCoord:(Branch *)branch
- This is the "meat" of the object. It receives a pointer to a branch
- and is expected to fill the branch with x,y,z coordinates and return.
- Several branch variables might be useful here : level contains the
- level of the current branch (starting with 0 at the root), root points
- to the Root structure where you can find the internet address, etc...
- The file "gopher.h" contains all of the structure definitions and
- explanations. This method is called whenever a new branch is created,
- and once for each branch just after this object is created.
-
- -preferences:sender
- You will receive this event whenever the user wants to change the
- preferences for this object. Feel free to ignore it if you don't
- have any. If you want to support some options, you'll need to create
- and load your own .nib file (more on this later).
-
- You may, of course implement any other methods you'd like ...
-
-
- implementing a "View" object is somewhat more time consuming. All of the
- following methods must be implemented :
-
- -initFrame:(NXRect *)myrect
- You don't really HAVE to implement this object, but it is a good place
- to do any initialization that needs to be done. Be sure to do a
- [super initframe:myrect] as the first step in your routine.
-
- -start:(Root *)Ptop :Pobject :(char *)path
- Just like the -start method for the "Coord" objects. It gives you
- access to the entire gopher web and to the main program object. In
- this case you will definitely need the Ptop pointer for refreshing
- the display, so be sure to save it.
-
- -step:(Branch *)myloc
- This method will be called several times each second (currently
- every .2 seconds). myloc points to the currently selected branch. You
- will need to update the display if necessary. You can also use this
- method for animation, etc ...
-
- -drawSelf:(NXRect *)rects :(int)rectCount
- This is the standard subview method which you must implement to
- do the actual drawing. It is not called directly by the main program,
- rather it is one of the methods that gets called when you call
- display. If you intend to draw a lot of lines,etc ... you should
- probably learn how to use DPSDoUserPath or your View may become
- unbearably slow.
-
- -refresh:(Branch *)myloc :(int)speed
- This method is expected to make the display current. If the user
- selects a new branch, this method must "move" the user to the
- new location. It is wise, therefore to store myloc in a static
- variable for the next time this method is called (so you can tell
- if you've moved). Sometimes -refresh is called with a NULL pointer.
- When this happens, you are expected to move (rapidly) to the top node
- in the web and redisplay. speed contains an integer from 0 ("jump" to
- the new location) to 100 (very slow flying to new location). Currently
- you will receive only a few discrete values in this range. 80 should
- be considered normal speed.
-
- -preferences:sender
- Just like the "Coord" method, you will receive this message when
- the user wants to change some preferences for your view. If you want
- to make use of this method, you'll probably need to make your
- own .nib file (more later). If you don't support any preferences, it's
- a good idea to say so in your "help" method, then have this method
- call help.
-
- -help:window :view
- Just like the Coord -help method.
-
-
- The only "global" preference that's currently supported is flying speed. If you
- don't want to load your own .nib file, there are a few other ways you can still
- allow the user to make some changes (see TreeView). By implementing the
- -acceptsFirstResponder, -keyDown, -keyUp, etc ... methods, you can allow the
- user to move around and/or change the way the view is displayed.
-
- For those of you who aren't big on data structures, the following fragment
- will climb the entire gopher web and call the DOIT routine exactly once for
- each Branch in the web :
-
- {
- Root *curr;
-
- for (curr=top; curr!=NULL; curr=curr->next) Climb(&curr->branch);
- }
-
- void Climb(Branch *branch)
- {
- Branch *cur;
-
- cur=branch;
-
- for (cur=branch; cur!=NULL; cur=cur->next) {
- DOIT(cur);
- /* don't forget cur->link when drawing */
- if (cur->sub!=NULL) Climb(cur->sub);
- return;
- }
-
-
- There are several useful methods supported by the main program's GopherObj
- which your objects should have access to :
-
- -top:sender
- Go to the top of the web and redisplay.
-
- -goto:(Branch *)branch
- Pretty obvious. This "moves" to the passed branch. It will send the
- necessary refresh messages and update the browsers.
-
- -(int)Read:(Branch *)branch
- This causes the passed branch to be read. If it is a directory, it
- is read in and added to the web. If it is a file it is read and
- displayed. Other types aren't supported yet.
-
- (float) frand((float)lo,(float)hi)
- This is actually a global subroutine you may use. It returns a floating
- point random number between lo and hi.
-
-
- If you think of any other useful methods I should implement, please let me know.
-
-
- Once you've written your object(s), follow the following steps to add them
- to Gopher in a Forest :
-
- 1. Compile and strip your object (see the included Makefile for
- necessary flags, etc...)
- 2. You can't add new objects to Gopher in a Forest while it's running yet
- (next release), so for now you'll have to do it manually. Move your .o
- and any .nib files to the Tree.app directory. Next, edit the "Prefs" file
- in the same directory and add the name of your object to the file. Coord
- objects go before the #, and View objects go after. The first line of the
- file is the default "root" host.
- 3. Run Tree from the command line.
- 4. Select your new object in one of the Forest browsers. If everything goes
- well (very unlikely), your object will be loaded and the results will
- be displayed. If something goes wrong with the dynamic loading, the
- errors will be displayed on stderr. If you can't figure out what the problem
- is, or if you think it's my fault (it very well may be at this point),
- send me some mail (steve@ion.rice.edu). You may also want to upload the
- problematical source to ion.rice.edu in the submissions directory.
-
- NOTE: Ignore the initial "objc: class `classname' not linked into the
- application" message. It will go away in the next release, and is not a bug.
- If you receive this message twice for the same object, THEN there is a
- problem ...
-
-